package jdbc;

import java.sql.*;
import java.util.Scanner;

public class RegDemo {
    public static void main(String[] args)  {
//        Class.forName("com.mysql.cj.jdbc.Driver");
//        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
//                "root", "root");

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名");
        String username = scanner.nextLine();
        System.out.println("请输入密码");
        String password = scanner.nextLine();
        System.out.println("请输入昵称");
        String nickname = scanner.nextLine();
        System.out.println("请输入年龄");
        int age = scanner.nextInt();

        String sql = "INSERT INTO userinfo (username, password, nickname, age) VALUES (?,?,?,?)";
        try(Connection connection = DBUtil.getConnection()) {
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, username);
            preparedStatement.setString(2, password);
            preparedStatement.setString(3, nickname);
            preparedStatement.setInt(4, age);
            int i = preparedStatement.executeUpdate();
            System.out.println(i>0?"修改成功":"修改失败");
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
